package cn.itcast.mytest;

import cn.itcast.n2.util.Sleeper;
import lombok.extern.slf4j.Slf4j;

@Slf4j(topic = "c.Test03")
public class Test03 {
    final static  Object obj = new Object();

    public static void main(String[] args) {
        new Thread(() -> {
            synchronized (obj){
                log.debug("执行");

                try {
                    obj.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            log.debug("其他代码");
        }, "t1").start();

        new Thread(() -> {
            synchronized (obj){
                log.debug("执行");

                try {
                    obj.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            log.debug("其他代码");
        }, "t2").start();

        Sleeper.sleep(0.5);

        synchronized (obj){
            obj.notifyAll();
        }

    }
}
